package pl.lodz.p.browarex.mvc;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import pl.lodz.p.browarex.model.User;
import pl.lodz.p.browarex.services.interfaces.ICustomerService;

@Controller
public class LoginUserController {

	@Inject
	ICustomerService customerService;

	@RequestMapping("/login")
	public String showLoginPage(Model model, HttpServletRequest request)
			throws Exception {

		model.addAttribute("user", new User());
		return "login";
	}

	@RequestMapping(value = "/trylogon", method = RequestMethod.POST)
	public String addContact(User user, BindingResult result) {

		System.out.println("login: " + user.getUsername() + "     pass: "
				+ user.getPassword());

		return "index";
	}

	@RequestMapping(value = "/loginfail", method = RequestMethod.GET)
	public String loginFail(Model model) {

		model.addAttribute("error", "true");

		return "login";
	}
}
